<?php
/**
 * Created by novebeta.
 * Date: 12/11/12
 * Time: 5:11 PM
 */
class EWebUser extends CWebUser{

    protected $_model;

    function isAdmin(){
        $user = $this->loadUser();
        if ($user)
            return $user->level==LevelUser::SUPERADMIN;
        return false;
    }

    function isHaveAccess($level=LevelUser::SUPERADMIN){
        $user = $this->loadUser();
        if($user->level==LevelUser::SUPERADMIN)
            return true;
        if(is_array($level)){
            return in_array($user->level,$level);
        }else{
            return $user->level>=$level;
        }
        return false;
    }

    // Load user model.
    protected function loadUser()
    {
        if ( $this->_model === null ) {
            $this->_model = Users::model()->findByPk( $this->id );
        }
        return $this->_model;
    }
}
